package com.learn.algorlthm;

import java.util.Stack;

/**
 * @classname:
 * @Description:包含min函数的栈
 * @author: yfpu(fengpu.yang @ ucarinc.com)
 * @Date: 2018-07-31 16:28
 * 题目描述：
 * 定义栈的数据结构，请在该类型中实现一个能够得到栈最小元素的 min 函数
 */
public class Learn30 {

    private static Stack<Long> dataStack = new Stack<>();
    private static Stack<Long> minStack = new Stack<>();

    public static void push(long node)
    {
        dataStack.push(node);
        minStack.push(minStack.isEmpty() ? node : Math.min(minStack.peek(), node));
    }

    public static void pop()
    {
        dataStack.pop();
        minStack.pop();
    }

    public static Long top()
    {
        return dataStack.peek();
    }

    public static Long min()
    {
        return minStack.peek();
    }
}
